﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Lk.Common.Result
{
    public enum StateCode
    {
        Success = 1,
        Fail = -1,
        NoData = 0,
    }

    public class ResultMessage
    {
        /// <summary>
        /// 状态 1成功,0无数据,-1 失败
        /// </summary>
        public int Status { set; get; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { set; get; }

        /// <summary> 时间戳 </summary>
        public DateTime TimeStamp => DateTime.Now;

        /// <summary> 返回消息，默认状态码1，消息ok </summary>
        public ResultMessage()
            : this(1, "OK")
        {
        }

        /// <summary> 指定返回消息 </summary>
        /// <param name="stateMessage">消息内容</param>
        public ResultMessage(string stateMessage)
            : this(1, stateMessage)
        {
        }

        /// <summary> 指定返回消息 </summary>
        /// <param name="stateCode"></param>
        /// <param name="stateMessage">消息内容</param>
        public ResultMessage(StateCode stateCode, string stateMessage)
            : this((int)stateCode, stateMessage)
        {
        }

        /// <summary> 创建指定状态码消息 </summary>
        /// <param name="stateCode">指定状态码</param>
        /// <param name="stateMessage">消息内容</param>
        public ResultMessage(int stateCode, string stateMessage)
        {
            Status = stateCode;
            Message = stateMessage;
        }
    }


    public class ResultMessage<T> : ResultMessage
    {
        /// <summary>
        /// 数据
        /// </summary>
        public T Data { set; get; }
        public ResultMessage(T d)
            : this(1, "OK", d)
        {
        }
        public ResultMessage(int stateCode, string stateMessage)
        {
            this.Status = stateCode;
            this.Message = stateMessage;
        }
        public ResultMessage(int stateCode, string stateMessage, T d)
        {
            this.Status = stateCode;
            this.Message = stateMessage;
            Data = d;
        }
    }
}
